package demo.spring.test180318Resources;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * @Author: tyzhang
 * @Description:
 * @Date: Created in 13:58 2018/3/18
 */
public class MoocResource implements ApplicationContextAware {
    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void resource() throws IOException {
        Resource resource = applicationContext.getResource("url:http://elim.iteye.com/blog/2016305");
        if (resource.isReadable()) {
            System.out.println(true);
        }
        if (resource.exists()) {
            long contentLength = resource.contentLength();
            System.out.println(resource.getFilename());
            System.out.println(contentLength);
        }
    }
}
